package cn.wolfcode.redis;

/*import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;*/

public class JedisTest {
    /*@Test
    public void testJedisPool() {
        // 1:创建Jedis连接池
        JedisPool pool = new JedisPool("localhost", 6379);
        // 2:从连接池中获取Jedis对象
        Jedis jedis = pool.getResource();
        *//* 设置密码
        jedis.auth(密码); *//*
        // 3:TODO
        System.out.println(jedis);
        // 4:关闭资源
        jedis.close();
        pool.destroy();

        jedis.set("name", "daijin");
        //System.out.println(jedis.get("name"));

        jedis.set("age","22");
        System.out.println(jedis.get("age"));
        jedis.incr("age");
        System.out.println(jedis.get("age"));
        jedis.decr("age");
        System.out.println(jedis.get("age"));
        jedis.del("name");
        System.out.println(jedis.get("name"));
        jedis.setex("nam",100,"haha");
        System.out.println(jedis.get("nam"));
        System.out.println(jedis.ttl("nam"));


    }
    @Test
    public void testJedisPool1() {
        // 1:创建Jedis连接池
        JedisPool pool = new JedisPool("localhost", 6379);
        // 2:从连接池中获取Jedis对象
        Jedis jedis = pool.getResource();
        *//* 设置密码
        jedis.auth(密码); *//*
        // 3:TODO
        System.out.println(jedis);
        // 4:关闭资源
        jedis.close();
        pool.destroy();

       // jedis.rpush("hobby","张三","李四","老王");
        System.out.println(jedis.lrange("hobby", 0, -1));
       // jedis.lpush("hobby","小敏");
        System.out.println(jedis.lrange("hobby", 0, -1));
        //jedis.rpush("hobby","大民");
        System.out.println(jedis.lrange("hobby", 0, -1));
        System.out.println(jedis.llen("hobby"));
        //System.out.println(jedis.lpop("hobby"));
        System.out.println(jedis.rpop("hobby"));
    }
    @Test
    public void testJedisPool2() {
        // 1:创建Jedis连接池
        JedisPool pool = new JedisPool("localhost", 6379);
        // 2:从连接池中获取Jedis对象
        Jedis jedis = pool.getResource();
        *//* 设置密码
        jedis.auth(密码); *//*
        // 3:TODO
        System.out.println(jedis);
        // 4:关闭资源
        jedis.close();
        pool.destroy();

       //jedis.sadd("set","jss","ssj");
        System.out.println(jedis.smembers("set"));
        //jedis.srem("set","js");
       // System.out.println(jedis.smembers("set"));
        //System.out.println(jedis.spop("set", 1));
        //jedis.sadd("set1","jss","ssj");
        System.out.println(jedis.smembers("set1"));
        //差集
        System.out.println(jedis.sdiff("set", "set1"));
        //交集
        System.out.println(jedis.sinter("set", "set1"));
        //并集
        System.out.println(jedis.sunion("set", "set1"));
        //集合中的元素个数
        System.out.println(jedis.scard("set"));
        System.out.println(jedis.scard("set1"));
    }
    @Test
    public void testJedisPool3() {
        // 1:创建Jedis连接池
        JedisPool pool = new JedisPool("localhost", 6379);
        // 2:从连接池中获取Jedis对象
        Jedis jedis = pool.getResource();
        *//* 设置密码
        jedis.auth(密码); *//*
        // 3:TODO
        System.out.println(jedis);
        // 4:关闭资源
        jedis.close();
        pool.destroy();

       *//*jedis.zadd("zset",1,"score1");
       jedis.zadd("zset",2,"score2");
       jedis.zadd("zset",2,"score3");*//*
       //按升序排名
        System.out.println(jedis.zrange("zset", 0, -1));
        //降序排名
        System.out.println(jedis.zrevrange("zset", 0, -1));
        //查看score1的降序排名
        System.out.println(jedis.zrevrank("zset", "score1"));
        //查看score1的升序排名
        System.out.println(jedis.zrank("zset", "score1"));
        System.out.println(jedis.zcard("zset"));


    }
    @Test
    public void testJedisPool4() {
         //创建 jedis 连接池
    JedisPool jedisPool = new JedisPool("localhost");
    //获取对象
    Jedis jedis = jedisPool.getResource();

    //Hash 类型
    //设置
        jedis.hset("user","name","neil");
        jedis.hset("user","age","meil");
        jedis.hset("user","sex","1");
    //获取
        System.out.println(jedis.hget("user", "name"));
        System.out.println(jedis.hget("user", "age"));
        System.out.println(jedis.hget("user", "sex"));
    // 判断hash对象是含有某个键
        System.out.println(jedis.hexists("user", "name"));
        System.out.println(jedis.hexists("user", "qqq"));

    //根据hashkey删除hash对象键值对
        jedis.hdel("user","name");
    //查询 数据
        System.out.println(jedis.hgetAll("user"));
        jedis.hdel("user","age");
        System.out.println(jedis.hgetAll("age"));
        jedis.close();
        jedisPool.destroy();


}

*/
}
